package cn.com.yang.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 自定义解析HTTP
 * TODO
 * @author yangyijin
 * @since 2023年5月13日-下午8:08:23
 */
public class SocketHttp80 {
	public static void main(String[] args) throws IOException {
		Socket httpd = new Socket("localhost",80);
		//创建请求流
		OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpd.getOutputStream());
		//写入信息
		 outputStreamWriter.write("GET /api/test.do?configId=5 HTTP/1.1\r\n");
        outputStreamWriter.write("Host:localhost\r\n");
        outputStreamWriter.write("Cookie:user_id=10001; timestamp=1623933567011; token=eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJVU0VSX0NFTlRFUiIsInN1YiI6IntcImlkXCI6MTAwMDEsXCJuYW1lXCI6XCLns7vnu5_nrqHnkIblkZhcIixcImVtYWlsXCI6XCJhZG1pbkBsaWx5ZW5nbGlzaC5jb21cIixcInBob25lXCI6XCIxNjgqKioqMDAwMFwiLFwic3RhdHVzXCI6MSxcInR5cGVcIjoyLFwibG9naW5EYXRlXCI6XCIyMDIxLTA2LTEzIDEwOjI5OjU2XCIsXCJleHBpcmVEYXRlXCI6XCIyMDIxLTA3LTEzIDEwOjI5OjU2XCIsXCJkdXJhdGlvblwiOjI1OTIwMDB9IiwiYXVkIjoiTElMWV9kZXYiLCJpYXQiOjE2MjM1NTEzOTYsImV4cCI6MTYyNjE0MzM5Nn0.nAEp47o61CDoY0yzB1wYuHImZtNKFwGqTUF-QGKxXpVPYV_bsKvJ1LHzA3LFjROrLoMXhttQX8UD1nyaazDPoA; source=employeecom.lily.usercenter.UserCenterApp");
        outputStreamWriter.write("\r\n");
        outputStreamWriter.write("\r\n");
        outputStreamWriter.flush();
        httpd.shutdownOutput();
        //获取输入流
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpd.getInputStream()));
        String line = null;
        //循环响应结果
        while((line=bufferedReader.readLine())!=null) {
        	System.out.println(line);
        }
        //关闭流
        outputStreamWriter.close();
        bufferedReader.close();
        httpd.close();
	}
}
